home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / comm / tcp / ATCP_src_22.lha / AmiTCP-2.2 / src / amitcp / sys / synch.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-12  |  4.8 KB  |  182 lines

  1. /*
  2.  * $Id: synch.h,v 1.17 1993/06/04 11:16:15 jraja Exp $
  3.  *
  4.  * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  5.  *                    Helsinki University of Technology, Finland.
  6.  *                    All rights reserved.
  7.  *
  8.  * HISTORY
  9.  * $Log: synch.h,v $
  10.  * Revision 1.17  1993/06/04  11:16:15  jraja
  11.  * Fixes for first public release.
  12.  *
  13.  * Revision 1.16  1993/05/24  19:28:56  ppessi
  14.  * Changed signal handling mechanism in tsleep_main() and WaitSelect()
  15.  *
  16.  * Revision 1.15  1993/05/17  01:02:04  ppessi
  17.  * Changed RCS version
  18.  *
  19.  * Revision 1.14  1993/04/19  22:35:05  jraja
  20.  * Fixed return value of splsoftclock(), splnet() and splimp() (with !DEBUG).
  21.  *
  22.  * Revision 1.13  93/04/13  22:01:32  22:01:32  jraja (Jarno Tapio Rajahalme)
  23.  * Added argument name to the spl_n prototype :-)
  24.  * 
  25.  * Revision 1.12  93/04/12  00:01:52  00:01:52  jraja (Jarno Tapio Rajahalme)
  26.  * Added ULONG *sigmp argument to tsleep_main().
  27.  * 
  28.  * Revision 1.11  93/04/05  15:00:50  15:00:50  jraja (Jarno Tapio Rajahalme)
  29.  * Added more efficient spl implementation when not debugging.
  30.  * Added spl return typedef spl_t.
  31.  * 
  32.  * Revision 1.10  93/04/05  09:31:33  09:31:33  jraja (Jarno Tapio Rajahalme)
  33.  * Changed includes to use <sys/time.h> (again) (by ppessi).
  34.  * 
  35.  * Revision 1.9  93/03/04  09:39:30  09:39:30  jraja (Jarno Tapio Rajahalme)
  36.  * Changed _AMIGA_API_H_ to AMIGA_API_H.
  37.  * 
  38.  * Revision 1.8  93/03/03  15:58:46  15:58:46  jraja (Jarno Tapio Rajahalme)
  39.  * Cleanup.
  40.  * 
  41.  * Revision 1.7  93/03/03  12:27:18  12:27:18  jraja (Jarno Tapio Rajahalme)
  42.  * Changed incomplete structure definitions to #includes
  43.  * 
  44.  * Revision 1.6  93/02/24  12:56:39  12:56:39  jraja (Jarno Tapio Rajahalme)
  45.  * Changed sleep_init() and spl_init() to return BOOL.
  46.  * 
  47.  * Revision 1.5  93/02/17  12:55:54  12:55:54  jraja (Jarno Tapio Rajahalme)
  48.  * Added prototypes for tsleep sub-functions.
  49.  * 
  50.  * Revision 1.4  93/02/04  18:19:47  18:19:47  jraja (Jarno Tapio Rajahalme)
  51.  * Added sleep_init(), tsleep() and wakeup() prototypes.
  52.  * Removed extern definitions of splsemaphore and spl_level, because they
  53.  * are needed only internally to kern/kern_synch.c.
  54.  * 
  55.  * Revision 1.3  92/12/22  00:12:16  00:12:16  jraja (Jarno Tapio Rajahalme)
  56.  * spl-definitions (written from scratch, really...)
  57.  * 
  58.  * Revision 1.2  92/11/20  15:57:01  15:57:01  jraja (Jarno Tapio Rajahalme)
  59.  * Added #ifndef AMITCP's to make this compile.
  60.  * 
  61.  * Revision 1.1  92/11/20  15:48:05  15:48:05  jraja (Jarno Tapio Rajahalme)
  62.  * Initial revision
  63.  * 
  64.  */
  65.  
  66. #ifndef SYS_SYNCH_H
  67. #define SYS_SYNCH_H
  68.  
  69. #ifndef SYS_TYPES_H
  70. #include <sys/types.h>
  71. #endif
  72.  
  73. #ifndef EXEC_TYPES_H
  74. #include <exec/types.h>
  75. #endif
  76.  
  77. #ifndef SYS_TIME_H
  78. #include <sys/time.h>
  79. #endif
  80.  
  81. #if !defined(AMIGA_INCLUDES_H) && !defined(DEBUG)
  82. #include <kern/amiga_includes.h> /* for the inline spl_n() */
  83. #endif
  84.  
  85. extern BOOL sleep_init(void);
  86. extern void tsleep_send_timeout(struct SocketBase *, const struct timeval *);
  87. extern void tsleep_abort_timeout(struct SocketBase *, const struct timeval *);
  88. extern void tsleep_enter(struct SocketBase *, caddr_t, char *);
  89. extern int  tsleep_main(struct SocketBase *, ULONG blockmask);
  90. extern int  tsleep(struct SocketBase *,caddr_t, char *,const struct timeval *);
  91. extern void wakeup(caddr_t);
  92.  
  93. /*
  94.  * Spl-levels used in this implementation
  95.  */
  96. #define SPL0         0
  97. #define SPLSOFTCLOCK 1
  98. #define SPLNET       2
  99. #define SPLIMP       3
  100.  
  101. /*
  102.  * Spl-function prototypes and definitions.
  103.  *
  104.  * spl_t is the return type of the spl_n(). It should be used when defining
  105.  * storage to store the return value, using int may be little slower :-) 
  106.  */
  107.  
  108. extern BOOL spl_init(void);
  109.  
  110. #ifdef DEBUG
  111.  
  112. typedef int spl_t;
  113.  
  114. extern spl_t spl_n(spl_t newlevel);
  115.  
  116. #define spl0()          spl_n(SPL0)
  117. #define splsoftclock()  spl_n(SPLSOFTCLOCK)
  118. #define splnet()        spl_n(SPLNET)
  119. #define splimp()        spl_n(SPLIMP)
  120. #define splx(s)         spl_n(s)
  121.  
  122. #else
  123.  
  124. typedef BYTE spl_t;        /* the type of SysBase->TDNestCnt */
  125.  
  126. extern struct ExecBase * SysBase;
  127.  
  128. static inline spl_t
  129. #if __SASC
  130. spl_n(int new_level)        /* int because SAS can't inline otherwise :( */
  131. #else
  132. spl_n(spl_t new_level)
  133. #endif
  134. {
  135.   spl_t old_level = SysBase->TDNestCnt;
  136.  
  137.   if (new_level != SPL0)
  138.     SysBase->TDNestCnt = new_level;
  139.   else {
  140.     SysBase->TDNestCnt = 1;
  141.     Permit();
  142.   }
  143.   return old_level;
  144. }
  145.  
  146. static inline spl_t
  147. #if __SASC
  148. spl_const(int new_level)    /* int because SAS can't inline otherwise :( */
  149. #else
  150. spl_const(spl_t new_level)
  151. #endif
  152. {
  153.   spl_t old_level = SysBase->TDNestCnt;
  154.  
  155.   SysBase->TDNestCnt = new_level;
  156.  
  157.   return old_level;
  158. }
  159.  
  160. static inline spl_t
  161. spl_0(void)
  162. {
  163.   spl_t oldlevel = SysBase->TDNestCnt;
  164.  
  165.   if (oldlevel != SPL0) {
  166.     SysBase->TDNestCnt = 1;
  167.     Permit();
  168.   }
  169.  
  170.   return oldlevel;
  171. }
  172.  
  173. #define spl0()          spl_0()
  174. #define splsoftclock()  spl_const(SPLSOFTCLOCK)
  175. #define splnet()        spl_const(SPLNET)
  176. #define splimp()        spl_const(SPLIMP)
  177. #define splx(s)         spl_n(s)
  178.  
  179. #endif /* DEBUG */
  180.  
  181. #endif /* !SYS_SYNCH_H */
  182.